package com.huidao.servlet.shoppingcart;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Goods;
import com.huidao.service.GoodsService;
import com.huidao.service.GoodsServiceImpl;
import com.huidao.service.ShoppingcartService;
import com.huidao.service.ShoppingcartServiceImpl;

/**
 * Servlet implementation class DelShoppingcartServlet
 */
public class DelShoppingcartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DelShoppingcartServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Long id=Long.parseLong(request.getParameter("id"));
		Long goodsId=Long.parseLong(request.getParameter("goodsId"));
		
		ShoppingcartService s=new ShoppingcartServiceImpl();
		
		Long num=Long.parseLong(request.getParameter("num"));
		
		Goods goods=new Goods();
		
		goods.setGoodsId(goodsId);
		GoodsService goodsService=new GoodsServiceImpl();
		
		Long Account=goodsService.getGoodsAccount(goods);
		goods.setGoodsAccount(num+Account);
		System.out.println(num);
		System.out.println(Account);
		String data=s.delShoppingcart(id);
		if(data.equals("")){
			//goodsService.updateGoodsAccount(goods);
			response.sendRedirect("GetShoppingcartListServlet?currentPage="+request.getParameter("currentPage"));
		}else{
			response.getWriter().print(data);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
